#ifndef __STMFLASH_H
#define __STMFLASH_H



typedef struct
{
    uint32_t StartTag;
    uint32_t FileSize;
    uint32_t FileCheckSum;
} firmwareinfo_t;

#define START_TAG                    0x1357ABCD
#define SECTOR_NUM                    3
#define FIRMWARE_START_SECTOR        FLASH_SECTOR_4
#define FIRMWARE_START_FLASH_ADDR     0x8080000
#define SECTOR_SIZE              0x20000
#define FIRMWARE_SIZE            SECTOR_SIZE*SECTOR_NUM
#define FIRMWARE_END_FLASH_ADDR       0x80BFFFF

#define FIRMWARE_UPDATE_FLASH_ADDR    0x80E0000

#define FLASH_RUN_APP_SECTOR        FLASH_SECTOR_1
#define FLASH_RUN_APP_START_ADDR    0x08020000
#define FLASH_RUN_APP_END_ADDR      0x0807ffff

#define STM32_FLASH_BASE 0x08000000 
#define FLASH_WAITETIME  50000 

//BANK1
#define ADDR_FLASH_SECTOR_0_BANK1     ((uint32_t)0x08000000) 
#define ADDR_FLASH_SECTOR_1_BANK1     ((uint32_t)0x08020000) 
#define ADDR_FLASH_SECTOR_2_BANK1     ((uint32_t)0x08040000) 
#define ADDR_FLASH_SECTOR_3_BANK1     ((uint32_t)0x08060000) 
#define ADDR_FLASH_SECTOR_4_BANK1     ((uint32_t)0x08080000) 
#define ADDR_FLASH_SECTOR_5_BANK1     ((uint32_t)0x080A0000) 
#define ADDR_FLASH_SECTOR_6_BANK1     ((uint32_t)0x080C0000) 
#define ADDR_FLASH_SECTOR_7_BANK1     ((uint32_t)0x080E0000) 

//BANK2
#define ADDR_FLASH_SECTOR_0_BANK2     ((uint32_t)0x08100000)
#define ADDR_FLASH_SECTOR_1_BANK2     ((uint32_t)0x08120000)
#define ADDR_FLASH_SECTOR_2_BANK2     ((uint32_t)0x08140000)
#define ADDR_FLASH_SECTOR_3_BANK2     ((uint32_t)0x08160000)
#define ADDR_FLASH_SECTOR_4_BANK2     ((uint32_t)0x08180000)
#define ADDR_FLASH_SECTOR_5_BANK2     ((uint32_t)0x081A0000)
#define ADDR_FLASH_SECTOR_6_BANK2     ((uint32_t)0x081C0000)
#define ADDR_FLASH_SECTOR_7_BANK2     ((uint32_t)0x081E0000)


uint32_t STMFLASH_ReadWord(uint32_t faddr);		  													
void STMFLASH_Read(uint32_t ReadAddr,uint32_t *pBuffer,uint32_t NumToRead);   		
uint8_t FLASHPara_Erase(uint32_t  sector);
void FLASH_Write(uint32_t WriteAddr,uint32_t *pBuffer,uint32_t NumToWrite);
int  NewAppSetblag(firmwareinfo_t *hdr);
void Loadappblag(void);
#endif
